home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- class TimerQueue implements Runnable {
- Timer firstTimer;
- boolean running;
- private static final Object sharedInstanceKey = new StringBuffer("TimerQueue.sharedInstanceKey");
- private static final Object expiredTimersKey = new StringBuffer("TimerQueue.expiredTimersKey");
- static Class class$com$sun$java$swing$TimerQueue;
-
- public TimerQueue() {
- this.start();
- }
-
- synchronized void addTimer(Timer timer, long expirationTime) {
- if (!timer.running) {
- Timer previousTimer = null;
-
- Timer nextTimer;
- for(nextTimer = this.firstTimer; nextTimer != null && nextTimer.expirationTime <= expirationTime; nextTimer = nextTimer.nextTimer) {
- previousTimer = nextTimer;
- }
-
- if (previousTimer == null) {
- this.firstTimer = timer;
- } else {
- previousTimer.nextTimer = timer;
- }
-
- timer.expirationTime = expirationTime;
- timer.nextTimer = nextTimer;
- timer.running = true;
- this.notify();
- }
- }
-
- synchronized boolean containsTimer(Timer timer) {
- return timer.running;
- }
-
- synchronized long postExpiredTimers() {
- long timeToWait;
- do {
- Timer timer = this.firstTimer;
- if (timer == null) {
- return 0L;
- }
-
- long currentTime = System.currentTimeMillis();
- timeToWait = timer.expirationTime - currentTime;
- if (timeToWait <= 0L) {
- try {
- timer.post();
- } catch (SecurityException var7) {
- }
-
- this.removeTimer(timer);
- if (timer.isRepeats()) {
- this.addTimer(timer, currentTime + (long)timer.getDelay());
- }
- }
-
- try {
- this.wait(1L);
- } catch (InterruptedException var6) {
- }
- } while(timeToWait <= 0L);
-
- return timeToWait;
- }
-
- synchronized void removeTimer(Timer timer) {
- if (timer.running) {
- Timer previousTimer = null;
- Timer nextTimer = this.firstTimer;
-
- boolean found;
- for(found = false; nextTimer != null; nextTimer = nextTimer.nextTimer) {
- if (nextTimer == timer) {
- found = true;
- break;
- }
-
- previousTimer = nextTimer;
- }
-
- if (found) {
- if (previousTimer == null) {
- this.firstTimer = timer.nextTimer;
- } else {
- previousTimer.nextTimer = timer.nextTimer;
- }
-
- timer.expirationTime = 0L;
- timer.nextTimer = null;
- timer.running = false;
- }
- }
- }
-
- public synchronized void run() {
- while(this.running) {
- long timeToWait = this.postExpiredTimers();
-
- try {
- this.wait(timeToWait);
- } catch (InterruptedException var3) {
- }
- }
-
- }
-
- public static TimerQueue sharedInstance() {
- Class var10000 = class$com$sun$java$swing$TimerQueue;
- if (var10000 == null) {
- try {
- var10000 = Class.forName("com.sun.java.swing.TimerQueue");
- } catch (ClassNotFoundException var3) {
- throw new NoClassDefFoundError(((Throwable)var3).getMessage());
- }
-
- class$com$sun$java$swing$TimerQueue = var10000;
- }
-
- synchronized(var10000) {
- TimerQueue sharedInst = (TimerQueue)SwingUtilities.appContextGet(sharedInstanceKey);
- if (sharedInst == null) {
- sharedInst = new TimerQueue();
- SwingUtilities.appContextPut(sharedInstanceKey, sharedInst);
- }
-
- return sharedInst;
- }
- }
-
- synchronized void start() {
- if (this.running) {
- throw new RuntimeException("Can't start a TimerQueue that is already running");
- } else {
- Thread timerThread = new Thread(this, "TimerQueue");
-
- try {
- timerThread.setDaemon(true);
- } catch (SecurityException var2) {
- }
-
- timerThread.start();
- this.running = true;
- }
- }
-
- synchronized void stop() {
- this.running = false;
- this.notify();
- }
-
- public synchronized String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append("TimerQueue (");
- Timer nextTimer = this.firstTimer;
-
- while(nextTimer != null) {
- buf.append(nextTimer.toString());
- nextTimer = nextTimer.nextTimer;
- if (nextTimer != null) {
- buf.append(", ");
- }
- }
-
- buf.append(")");
- return buf.toString();
- }
- }
-